#!/bin/bash

function template_docker_compose() {
  cat <<EOL
version: '3'

networks:
  default:

services:
EOL
}

function template_nginx() {
  cat <<EOL
  nginx:
    image: nginx:alpine
    container_name: nginx
    restart: always
    networks:
      - default
    ports:
      - \${NGINX_MACHINE_HTTP_PORT}:\${NGINX_CONTAINER_HTTP_PORT}
      - \${NGINX_MACHINE_HTTPS_PORT}:\${NGINX_CONTAINER_HTTPS_PORT}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${NGINX_MACHINE_CONFIG}:\${NGINX_CONTAINER_CONFIG}:ro
      - \${NGINX_MACHINE_CERTS}:\${NGINX_CONTAINER_CERTS}:rw
      - \${NGINX_MACHINE_VHOSTS}:\${NGINX_CONTAINER_VHOSTS}:rw
      - \${DIR_MACHINE_WWW}:\${DIR_CONTAINER_WWW}:rw
      - \${DIR_MACHINE_LOGS}:\${DIR_CONTAINER_LOGS}:rw
EOL
}

function template_mysql() {
  cat <<EOL
  mysql:
    build:
      context: ./build
      dockerfile: dockerfile/mysql
      args:
        MYSQL_VERSION: \${MYSQL_VERSION}
        PERCONA_XTRABACKUP_VERSION: \${MYSQL_PERCONA_XTRABACKUP_VERSION}
    container_name: mysql
    restart: always
    networks:
      - default
    ports:
      - \${MYSQL_MACHINE_PORT}:\${MYSQL_CONTAINER_PORT}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${MYSQL_MACHINE_CONFIG}:\${MYSQL_CONTAINER_CONFIG}:ro
      - \${MYSQL_MACHINE_DATA}:\${MYSQL_CONTAINER_DATA}:rw
    environment:
      MYSQL_ROOT_PASSWORD: \${MYSQL_PASSWORD}
EOL
}

function template_mongo() {
  cat <<EOL
  mongo:
    image: mongo:latest
    container_name: mongo
    restart: always
    networks:
      - default
    ports:
      - \${MONGO_MACHINE_PORT}:\${MONGO_CONTAINER_PORT}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${MONGO_MACHINE_CONFIG}:\${MONGO_CONTAINER_CONFIG}:ro
      - \${MONGO_MACHINE_DATA}:\${MONGO_CONTAINER_DATA}:rw
      - \${DIR_MACHINE_LOGS}:\${DIR_CONTAINER_LOGS}:rw
    entrypoint: \${MONGO_ENTRYPOINT}
EOL
}

function template_redis() {
  cat <<EOL
  redis:
    image: redis:alpine
    container_name: redis
    restart: always
    networks:
      - default
    ports:
      - \${REDIS_MACHINE_PORT}:\${REDIS_CONTAINER_PORT}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${REDIS_MACHINE_CONFIG}:\${REDIS_CONTAINER_CONFIG}:ro
      - \${REDIS_MACHINE_DATA}:\${REDIS_CONTAINER_DATA}:rw
      - \${DIR_MACHINE_LOGS}:\${DIR_CONTAINER_LOGS}:rw
    entrypoint: \${REDIS_ENTRYPOINT}
    sysctls:
      net.core.somaxconn: \${REDIS_SYSCTLS_NET_CORE_SOMAXCONN}
EOL
}

function template_rabbitmq() {
  cat <<EOL
  rabbitmq:
    image: rabbitmq:management-alpine
    container_name: rabbitmq
    restart: always
    networks:
      - default
    ports:
      - \${RABBITMQ_MACHINE_PORT}:\${RABBITMQ_CONTAINER_PORT}
      - \${RABBITMQ_MACHINE_MANAGEMENT_PORT}:\${RABBITMQ_CONTAINER_MANAGEMENT_PORT}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${RABBITMQ_MACHINE_CONFIG}:\${RABBITMQ_CONTAINER_CONFIG}:ro
      - \${RABBITMQ_MACHINE_DATA}:\${RABBITMQ_CONTAINER_DATA}:rw
EOL
}

function template_php56() {
  cat <<EOL
  php56:
    build:
      context: ./build
      dockerfile: dockerfile/php
      args:
        PHP_VERSION: \${PHP56_VERSION}
        ALPINE_VERSION: \${ALPINE_VERSION}
        ALPINE_REPOSITORIES: \${ALPINE_REPOSITORIES}
        PHP_COMPOSER_DIR: \${PHP_CONTAINER_COMPOSER_DIR}
        PHP_EXTENSIONS: \${PHP56_EXTENSIONS}
        MORE_EXTENSION_INSTALLER: \${PHP56_MORE_EXTENSION_INSTALLERS}
        IMAGICK_VERSION: \${PHP_IMAGICK_VERSION}
        INOTIFY_VERSION: \${PHP56_INOTIFY_VERSION}
        MCRYPT_VERSION: \${PHP56_MCRYPT_VERSION}
        MONGODB_VERSION: \${PHP56_MONGODB_VERSION}
        REDIS_VERSION: \${PHP56_REDIS_VERSION}
        SQLSRV_VERSION: \${PHP56_SQLSRV_VERSION}
        SQLSRV_SOFTWARE_VERSION: \${PHP_SQLSRV_SOFTWARE_VERSION}
        SWOOLE_VERSION: \${PHP56_SWOOLE_VERSION}
        XHPROF_VERSION: \${PHP56_XHPROF_VERSION}
        YAF_VERSION: \${PHP56_YAF_VERSION}
        CODE_SNIFFER_VERSION: \${PHP_CODE_SNIFFER_VERSION}
        CS_FIXER_VERSION: \${PHP_CS_FIXER_VERSION}
        PHPMD_VERSION: \${PHP_PHPMD_VERSION}
        PHPSTAN_VERSION: \${PHP_PHPSTAN_VERSION}
        PSALM_VERSION: \${PHP_PSALM_VERSION}
    container_name: \${PHP56_NAME}
    restart: always
    networks:
      - default
    expose:
      - \${PHP56_EXPOSE}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${MACHINE_PASSWD}:\${CONTAINER_PASSWD}:ro
      - \${MACHINE_GROUP}:\${CONTAINER_GROUP}:ro
      - \${PHP_MACHINE_INI}:\${PHP_CONTAINER_INI}:ro
      - \${PHP_MACHINE_FPM_CONFIG}:\${PHP_CONTAINER_FPM_CONFIG}:ro
      - \${PHP_MACHINE_COMPOSER_DIR}:\${PHP_CONTAINER_COMPOSER_DIR}:rw
      - \${DIR_MACHINE_WWW}:\${DIR_CONTAINER_WWW}:rw
      - \${DIR_MACHINE_LOGS}:\${DIR_CONTAINER_LOGS}:rw
EOL
}

function template_php73() {
  cat <<EOL
  php73:
    build:
      context: ./build
      dockerfile: dockerfile/php
      args:
        PHP_VERSION: \${PHP73_VERSION}
        ALPINE_VERSION: \${ALPINE_VERSION}
        ALPINE_REPOSITORIES: \${ALPINE_REPOSITORIES}
        PHP_COMPOSER_DIR: \${PHP_CONTAINER_COMPOSER_DIR}
        PHP_EXTENSIONS: \${PHP73_EXTENSIONS}
        MORE_EXTENSION_INSTALLER: \${PHP73_MORE_EXTENSION_INSTALLERS}
        IMAGICK_VERSION: \${PHP_IMAGICK_VERSION}
        INOTIFY_VERSION: \${PHP73_INOTIFY_VERSION}
        MCRYPT_VERSION: \${PHP73_MCRYPT_VERSION}
        MONGODB_VERSION: \${PHP73_MONGODB_VERSION}
        REDIS_VERSION: \${PHP73_REDIS_VERSION}
        SQLSRV_VERSION: \${PHP73_SQLSRV_VERSION}
        SQLSRV_SOFTWARE_VERSION: \${PHP_SQLSRV_SOFTWARE_VERSION}
        SWOOLE_VERSION: \${PHP73_SWOOLE_VERSION}
        XHPROF_VERSION: \${PHP73_XHPROF_VERSION}
        YAF_VERSION: \${PHP73_YAF_VERSION}
        CODE_SNIFFER_VERSION: \${PHP_CODE_SNIFFER_VERSION}
        CS_FIXER_VERSION: \${PHP_CS_FIXER_VERSION}
        PHPMD_VERSION: \${PHP_PHPMD_VERSION}
        PHPSTAN_VERSION: \${PHP_PHPSTAN_VERSION}
        PSALM_VERSION: \${PHP_PSALM_VERSION}
    container_name: \${PHP73_NAME}
    restart: always
    networks:
      - default
    expose:
      - \${PHP73_EXPOSE}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${MACHINE_PASSWD}:\${CONTAINER_PASSWD}:ro
      - \${MACHINE_GROUP}:\${CONTAINER_GROUP}:ro
      - \${PHP_MACHINE_INI}:\${PHP_CONTAINER_INI}:ro
      - \${PHP_MACHINE_FPM_CONFIG}:\${PHP_CONTAINER_FPM_CONFIG}:ro
      - \${PHP_MACHINE_COMPOSER_DIR}:\${PHP_CONTAINER_COMPOSER_DIR}:rw
      - \${DIR_MACHINE_WWW}:\${DIR_CONTAINER_WWW}:rw
      - \${DIR_MACHINE_LOGS}:\${DIR_CONTAINER_LOGS}:rw
EOL
}

function template_php74() {
  cat <<EOL
  php74:
    build:
      context: ./build
      dockerfile: dockerfile/php
      args:
        PHP_VERSION: \${PHP74_VERSION}
        ALPINE_VERSION: \${ALPINE_VERSION}
        ALPINE_REPOSITORIES: \${ALPINE_REPOSITORIES}
        PHP_COMPOSER_DIR: \${PHP_CONTAINER_COMPOSER_DIR}
        PHP_EXTENSIONS: \${PHP74_EXTENSIONS}
        MORE_EXTENSION_INSTALLER: \${PHP74_MORE_EXTENSION_INSTALLERS}
        IMAGICK_VERSION: \${PHP_IMAGICK_VERSION}
        INOTIFY_VERSION: \${PHP74_INOTIFY_VERSION}
        MCRYPT_VERSION: \${PHP74_MCRYPT_VERSION}
        MONGODB_VERSION: \${PHP74_MONGODB_VERSION}
        REDIS_VERSION: \${PHP74_REDIS_VERSION}
        SQLSRV_VERSION: \${PHP74_SQLSRV_VERSION}
        SQLSRV_SOFTWARE_VERSION: \${PHP_SQLSRV_SOFTWARE_VERSION}
        SWOOLE_VERSION: \${PHP74_SWOOLE_VERSION}
        XHPROF_VERSION: \${PHP74_XHPROF_VERSION}
        YAF_VERSION: \${PHP74_YAF_VERSION}
        CODE_SNIFFER_VERSION: \${PHP_CODE_SNIFFER_VERSION}
        CS_FIXER_VERSION: \${PHP_CS_FIXER_VERSION}
        PHPMD_VERSION: \${PHP_PHPMD_VERSION}
        PHPSTAN_VERSION: \${PHP_PHPSTAN_VERSION}
        PSALM_VERSION: \${PHP_PSALM_VERSION}
    container_name: \${PHP74_NAME}
    restart: always
    networks:
      - default
    expose:
      - \${PHP74_EXPOSE}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${MACHINE_PASSWD}:\${CONTAINER_PASSWD}:ro
      - \${MACHINE_GROUP}:\${CONTAINER_GROUP}:ro
      - \${PHP_MACHINE_INI}:\${PHP_CONTAINER_INI}:ro
      - \${PHP_MACHINE_FPM_CONFIG}:\${PHP_CONTAINER_FPM_CONFIG}:ro
      - \${PHP_MACHINE_COMPOSER_DIR}:\${PHP_CONTAINER_COMPOSER_DIR}:rw
      - \${DIR_MACHINE_WWW}:\${DIR_CONTAINER_WWW}:rw
      - \${DIR_MACHINE_LOGS}:\${DIR_CONTAINER_LOGS}:rw
EOL
}

function template_php80() {
  cat <<EOL
  php80:
    build:
      context: ./build
      dockerfile: dockerfile/php
      args:
        PHP_VERSION: \${PHP80_VERSION}
        ALPINE_VERSION: \${ALPINE_VERSION}
        ALPINE_REPOSITORIES: \${ALPINE_REPOSITORIES}
        PHP_COMPOSER_DIR: \${PHP_CONTAINER_COMPOSER_DIR}
        PHP_EXTENSIONS: \${PHP80_EXTENSIONS}
        MORE_EXTENSION_INSTALLER: \${PHP80_MORE_EXTENSION_INSTALLERS}
        IMAGICK_VERSION: \${PHP_IMAGICK_VERSION}
        INOTIFY_VERSION: \${PHP80_INOTIFY_VERSION}
        MCRYPT_VERSION: \${PHP80_MCRYPT_VERSION}
        MONGODB_VERSION: \${PHP80_MONGODB_VERSION}
        REDIS_VERSION: \${PHP80_REDIS_VERSION}
        SQLSRV_VERSION: \${PHP80_SQLSRV_VERSION}
        SQLSRV_SOFTWARE_VERSION: \${PHP_SQLSRV_SOFTWARE_VERSION}
        SWOOLE_VERSION: \${PHP80_SWOOLE_VERSION}
        XHPROF_VERSION: \${PHP80_XHPROF_VERSION}
        YAF_VERSION: \${PHP80_YAF_VERSION}
        CODE_SNIFFER_VERSION: \${PHP_CODE_SNIFFER_VERSION}
        CS_FIXER_VERSION: \${PHP_CS_FIXER_VERSION}
        PHPMD_VERSION: \${PHP_PHPMD_VERSION}
        PHPSTAN_VERSION: \${PHP_PHPSTAN_VERSION}
        PSALM_VERSION: \${PHP_PSALM_VERSION}
    container_name: \${PHP80_NAME}
    restart: always
    networks:
      - default
    expose:
      - \${PHP80_EXPOSE}
    volumes:
      - \${MACHINE_LOCALTIME}:\${CONTAINER_LOCALTIME}:ro
      - \${MACHINE_TIMEZONE}:\${CONTAINER_TIMEZONE}:ro
      - \${MACHINE_PASSWD}:\${CONTAINER_PASSWD}:ro
      - \${MACHINE_GROUP}:\${CONTAINER_GROUP}:ro
      - \${PHP_MACHINE_INI}:\${PHP_CONTAINER_INI}:ro
      - \${PHP_MACHINE_FPM_CONFIG}:\${PHP_CONTAINER_FPM_CONFIG}:ro
      - \${PHP_MACHINE_COMPOSER_DIR}:\${PHP_CONTAINER_COMPOSER_DIR}:rw
      - \${DIR_MACHINE_WWW}:\${DIR_CONTAINER_WWW}:rw
      - \${DIR_MACHINE_LOGS}:\${DIR_CONTAINER_LOGS}:rw
EOL
}
